<?php

/**
 * Message form.
 *
 * @package    maximous
 * @subpackage form
 * @author     Mina.Gerges.Wadea
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class MessageForm extends BaseMessageForm
{

    public function configure()
    {
        $i18n = $this->getOption('i18n');
        $this->setWidget('content', new sfWidgetFormTextarea());
        $this->useFields(array('title', 'content', 'to_user_id'));
        $this->getWidget('to_user_id')->addOption('query', UserTable::getInstance()->getAllUserExceptThisId($this->getOption('maxUser')->getUserDataByIndex('id')));
        $this->configureLoginUserRoleOnChangeStatusAndNeedCheck();
        $this->addFormatter('CustomFormatter');
    }

    public function doSave($con = null)
    {
        $this->getObject()->setUserId($this->getOption('maxUser')->getUserDataByIndex('id'));
        $this->getObject()->setStatues(Message::UNREADED);
        parent::doSave($con);
    }

    public function removeToUserFiled()
    {
        unset($this['to_user_id']);
    }

    public function save($con = null)
    {
        parent::save($con);
        // after save send message to user
    }

}
